package ws.jdbc.concurrent.driver.sqlserver.tds.rpc;

import ws.jdbc.concurrent.driver.sqlserver.tds.datatypes.TYPE_VARBYTE;
import ws.jdbc.concurrent.driver.sqlserver.tds.datatypes.TYPE_VARLEN;
import ws.utils.ArrayUtil;

/**
 *
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
public class ParamLenData {
private TYPE_VARBYTE data;

  public ParamLenData(byte varlentype) {
    this.data = new TYPE_VARBYTE(TYPE_VARLEN.create(varlentype, 0), new byte[0]);
  }

  public ParamLenData(byte[] data, byte varlentype) {
    this.data = new TYPE_VARBYTE(TYPE_VARLEN.create(varlentype, data.length), data);
  }

  public ParamLenData(String data, byte varlentype) {
    this.data = new TYPE_VARBYTE(TYPE_VARLEN.create(varlentype, 2 * data.length()), ArrayUtil.toLittleEndian(data));
  }

  public ParamLenData(int data) {
    this.data = new TYPE_VARBYTE(data);
  }

  public byte[] getBytes() {
    return data.getBytes();
  }

  public int size() {
    return data.size();
  }

  public TYPE_VARLEN getTypeVarLen() {
    return data.getTypeVarlen();
  }
}
